<?php
$menu = 'teachhour';
include_once 'head.php';
//管理员授权//////////////////
include_once 'dbconfig.php';

if (filter_input(INPUT_GET, 'id')) {
    // 查询数据
  
    $statement = "select * from teachhour where id=:id"; 
    $data2 = array(
        "id" => $_GET['id']
    );
    $statementObject = $pdo->prepare($statement);
    $statementObject->execute($data2);
    $result = $statementObject->fetch();
    if (! $result) {
        header("location:jump.php?error=无有效数据&url=teachhour.php&wait=2");
    }

} elseif (filter_input(INPUT_POST, 'year')) {
    //保存提交的数据
    $data = $_POST;
    //强制数据状态
    if($data["status"]=="送审"){
        $data["status"]="待审";
    }
    $statement = "update teachhour set year=:year,status=:status,teacherId=:teacherId,".
        "classHour=:classHour where id=:id";
    $statementObject = $pdo->prepare($statement);
    $result = $statementObject->execute($data);
    if ($result) {
        header("location:jump.php?error=数据保存成功&url=teachhour.php&wait=2");
    } else {
        header("location:jump.php?error=数据保存失败&url=teachhour.php&wait=2");
    }
    exit();
}


//查询basedata3中年份
$statementObject = $pdo->prepare("select * from basedata3");
$statementObject->execute();
$basedata3 = $statementObject->fetch(PDO::FETCH_ASSOC);
$workYear = $basedata3['content'];

?>
<script src="assets/js/hu.js"></script>
<script>
function pickName()
{
    window.open("pickname.php","_blank",
        "height=100,width=400,left=300,top=500,location=no,"+
        "menubar=no,titlebar=no,toolbar=no,resizable=no,scrollbars=no"
    );
}

//前端做数据完整性校验
function mysubmit(submitType) {
	//读取数据
	var classHour = document.getElementById("classHour").value;
	if(classHour==""){
		alert("数据不完整，请数据补充完整！");
	}else{
		//数据范围校验
		var isok = true;
		var textobj =  document.getElementById("classHour");
		textobj.value=textobj.value.replace(/([\d-]+)[\D]|[^-^\d]/g,"$1");
		if(textobj.value==""){
			alert("课时量必须填入整数");
		}else{
			var workform = document.getElementById("workform");
			var status = document.getElementById("status");
			if(submitType.name=="save"){
				status.value="保存";
			}else if(submitType.name=="submitCheck"){
				status.value="待审";
			}else if(submitType.name=="ok"){
				status.value="确认";
			}
			workform.submit();
		}
	}
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try{
     	//Firefox, Opera 8.0+, Safari
     	xmlHttp=new XMLHttpRequest();
    }catch (e){
        // Internet Explorer
        try{
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function checkRange(textobj){
	textobj.value=textobj.value.replace(/([\d-]+)[\D]|[^-^\d]/g,"$1");
}
</script>
<div id="page-wrapper">
	<div id="page-inner">
		<div class="row">
			<div class="col-md-12">
				<h2 align='center'>修改非授课工作量</h2>
			</div>
		</div>
		<!-- /. ROW  -->
		<hr />
		<div class="row">
			<div class="col-md-8 col-md-offset-2 col-sm-12 col-sm-offset-0 col-xs-10 col-xs-offset-2">
				<div class="panel panel-default">
			<div
				class="col-md-8 col-md-offset-2 col-sm-12 col-sm-offset-0 col-xs-10 col-xs-offset-2">
				<div class="panel panel-default">
					<div class="panel-heading">
						<strong>录入教学工作量</strong>
					</div>
					<div class="panel-body">
							<form role="form" id="workform" action="editteachhour2.php" method='post'>
						    <input type="hidden" name='id' id='id' value='<?php echo $_GET['id'];?>'/>
							<br />
							<div class="form-group input-group">
								<span class="input-group-addon"><i class="fa fa-tag"> 年度</i></span>
								<select class="form-control" name="year">
            						<option value="0" >全部</option>
            						<option value="2018"  <?php if($result['year']==2018){ echo "selected";}?>>2018年</option>
            						<option value="2019"  <?php if($result['year']==2019){ echo "selected";}?>>2019年</option>
            						<option value="2020 "<?php if($result['year']==2020){ echo "selected";}?> >2020年</option>
            						<option value="2021 "<?php if($result['year']==2021){ echo "selected";}?> >2021年</option>
            						<option value="2022 " <?php if($result['year']==2022){ echo "selected";}?>>2022年</option>
            					</select>
								<span class="input-group-addon"><i class="fa fa-flag">&nbsp;教工号</i></span>
								<input type="text" class="form-control" placeholder="教工号" name='teacherId' maxlength="15" id='teacherId' onclick="pickName()"  value="<?=$_SESSION['userLogined']?>"/>
							</div>
							<div class="form-group input-group">
								<span class="input-group-addon"><i class="fa fa-clock-o">&nbsp; 课时</i></span>
								<input type="text" class="form-control" id="classHour" maxlength="10"   value=<?php echo $result['classHour']?>
									name='classHour'  onkeyup="checkRange(this)"/>
							</div>
							<input type="hidden" id="status" name="status" value="保存"/>
 							<input type='reset' class="btn btn-primary" value=' 重 置 ' />&nbsp;&nbsp;
							<input type='button' name="ok" onclick="javascript:mysubmit(this);" class="btn btn-primary" value=' 确认 ' />&nbsp;&nbsp;
						<a class="btn btn-primary" href="index.php">放弃</a>
						</form>
						
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div id="foot-wrapper" align='center'>
			版权所有@2017-<?=date("Y")?>，计算机与设计学院<br /> 非授课工作量管理系统，网址：<a
		href='www.betgod.top/workload'>www.betgod.top/workload</a> <br /> <br />
</div>
<!-- /. PAGE WRAPPER  -->
<!-- /. WRAPPER  -->
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<!-- JQUERY SCRIPTS -->
<script src="./assets/js/jquery-1.10.2.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="./assets/js/bootstrap.min.js"></script>
<!-- METISMENU SCRIPTS -->
<script src="./assets/js/jquery.metisMenu.js"></script>
</body>
</html>